package com.xinjie.www.service.report;

import com.xinjie.www.dao.BaseDao;
import com.xinjie.www.dao.report.ReportDao;
import com.xinjie.www.dao.report.ReportDaoImpl;
import com.xinjie.www.po.Report;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ReportServiceImpl implements ReportService {
    private final ReportDao reportDao;

    public ReportServiceImpl() {
        reportDao = new ReportDaoImpl();
    }

    @Override
    public boolean doReport(int postId, int userId) throws SQLException, ClassNotFoundException {
        Connection conn = null;
        conn = BaseDao.getConnection();
        boolean flag = false;
        if (conn != null) {
            int i = reportDao.doReport(conn, postId, userId);
            if (i > 0) {
                flag = true;
            }
            BaseDao.closeResource(conn, null, null);
        }
        return flag;
    }

    @Override
    public List<Report> getReport(String tieba) throws SQLException, ClassNotFoundException {
        Connection conn = null;
        conn = BaseDao.getConnection();
        List<Report> reports = new ArrayList<>();
        System.out.println(tieba);
        if (conn != null) {
            reports = reportDao.getReport(conn, tieba);
            BaseDao.closeResource(conn, null, null);
        }
        return reports;
    }
}
